package calvin.study.rabbitmq.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import calvin.study.rabbitmq.model.order.Order;
import calvin.study.rabbitmq.service.order.IOrderService;
import ch.qos.logback.core.util.TimeUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;

@RestController
@RequestMapping("test")
public class TestController {
	
	@GetMapping("/hello")
	public String hello() {
		return "hello";
	}
	
	
	@Autowired
	private IOrderService orderService;

	@GetMapping("/order/{product}")
	public void order(@PathVariable Integer product) throws Exception {
		Order order = new Order();
		Snowflake snowflake = IdUtil.getSnowflake(1, 1);
		
		order.setOrderId(snowflake.nextIdStr());
		order.setOrderName("测试商品"+DateUtil.today());
		order.setProductId(product);
		order.setCreateTime(DateUtil.date());
		order.setUpdateTime(DateUtil.date());
		orderService.createOrder(order);
	}
	
	public static void main(String[] args) {
		System.out.println(DateUtil.today());
	}
}
